<?php 

Yii::import('application.modules.video.extensions.jPlayerWidget');

$tags = TagTypes::model()->findAll();
$tagString = '';
$totalNumVotes = VoteUserDetails::Model()->count('id');
foreach ($tags as $tag) {
	//$tagString .= 	"{ id: ".$tag->id.", toString: function() { return '".$tag->tag."'; } },";        
    $tagString .= "{ id: ".$tag->id.", value: '".$tag->tag."'},";        
}

echo "<div id=\"video-wrapper\">";
// Display all videos
	if(!empty($videos))
	{	
		foreach ($videos as $model) 
		{
			
				//$mediaStream = explode('|', $model->contentFiles->file_name);
		        //for getting status of videos//
		        $stat = $model->contentStatus->find(array('select'=>'name','condition'=>'id=:id','params'=>array(':id'=>$model->contentStatus->id)));
		        $status = (isset($stat['name'])) ? $stat['name'] : 'Pending';

		    if($model->content_status_id != 1){
		        ///for getting status of videos//
		        echo '<div class="players">';
					jPlayerWidget::renderjPlyer($model->contentFiles->file_name, $model->contentFiles->id);
					echo "<div class=\"row\">";
						echo "<div class=\"row-left\">";
							echo "<div class=\"row-checkBox\">";
								echo '<input type="checkbox" name="ContentStatus['.$model->id.']" id="video_'.$status.'[]" value="on" />'; 
					        	//echo CHtml::activeCheckBox($model,'content_status_id');//array('value'=>$model->contentFiles->id, 'id'=>'video_'.$model->contentFiles->id, 'name'=>'video_'.$status.'[]'));
					        echo "</div>";
				        echo "</div>";
				        echo "<div class=\"row-right\">";
					        echo "<div class=\"row-title\">";  
					        	//echo Content::getFileName($model->contentFiles->file_name).ZencoderVideoEncoder::OUTPUT_FORMAT;
					        	$this->beginWidget('CHtmlPurifier');                                                  
                                  echo substr($model->userDetails->name,0,20);
								$this->endWidget();	
					        echo "</div>";
					        echo "<div class=\"row-status\">";	                       
		                        echo $status;
		                        if (!empty($model->modified_date)) echo ' ('. date('d/m/Y',strtotime($model->modified_date)).')';
					        echo "</div>";
					        echo "<div class=\"row-state\">";
					        	echo 'Birth Year: '.$model->userDetails->birth_year.'</br>';
					        	echo 'State: '. Content::model()->getFullStateName($model->userDetails->state) ;
					        echo "</div>"; 
					        echo "<div class=\"row-createdDate\">";
					        	//$this->beginWidget('CHtmlPurifier'); 
					        		//echo 'User: ' . substr($model->userDetails->name,0,20);
					        		
                                     $vote = Votes::model()->findByAttributes(array('user_details_id'=>$model->userDetails->id ));
                                     $stars = 0;
                                     $numVotes = 0;
                                     if($vote){
                                     	//$stars = ($vote->num_votes / Votes::model()->getTotalVotes()) * 5;
                                     	$stars = ($vote->score_votes / $vote->num_votes);
                                     	$numVotes = $vote->num_votes;
                                     }                                   
                                     ?>	                                     
										<div class="exemple">										
											<div class="exemple4" id="<?php echo $stars.'_'.$model->userDetails->id ?>"></div><div class="total_votes">Votes: <?php echo $numVotes."/$totalNumVotes"; ?></div>
										</div>
										<?php 
										 $spantext = 'More Info'."
                                                <span class='hover'>
                                                    <strong>".$model->userDetails->name."</strong><br />".
                                                    "Birth Year: ". $model->userDetails->birth_year."<br />".
                                                    "Email: ". $model->userDetails->email."<br />".
					        		 				"State: ". $model->userDetails->state."<br />".
										 			"File: ". Content::getFileName($model->contentFiles->file_name).ZencoderVideoEncoder::OUTPUT_FORMAT."<br />".
                                                "</span>";
                                                    
                                     echo(CHtml::link($spantext, array('default/bio', 'id' => $model->userDetails->id), array('class'=>'hovery')));
                                     ?>
									</div>
									</div>
									<div>
										<div id=<?php echo 'tags_'.$model->userDetails->id?> class=tagSelector style="width:165px;max-height: 24px;">											
												<?php 
													$tagModel = Tags::model()->findByAttributes(array('user_details_id'=>$model->userDetails->id));
													if($tagModel){
													echo '<span class=tag>';
													echo $tagModel->tags.'<a>&times</a>';
													echo '<input name=tags type=hidden></span>';													
													}													
												?>											
											<input type=text>
										</div>
										
										<?php echo "<script> $(function() {                                                                                                        
													var tags = [
														".$tagString."
													];
													$('#tags_".$model->userDetails->id."').tagSelector(tags, 'tags', ".$model->userDetails->id.");												
												});	</script>"; 
											?>								
                                     <?php                                              
                                     
                                     //	var_dump($vote->num_votes);
					        	//$this->endWidget();				        	
					        echo "</div>";  
					   //echo "</div>"; 
				    echo "</div>";            
		
		       	echo '</div>';
			}
		}
	}else{
		echo "<br class='clear' />";
		echo '<h2>No Videos found..</h2>';
	}
			
echo "</div>";
echo "<br class='clear' />";

$this->widget('CLinkPager', array(
    'pages' => $pages,
	'cssFile' => Yii::app()->theme->baseUrl.'/css/pager.css',
	)); 

echo "<div class=\"button_section\"></div>";
   //echo CHtml::submitButton('Submit', array('class'=>'save'));

	
echo CHtml::endForm();
echo "</div>";	
?>
